<template>
    <div>
        <h1>
            <span>{{ $t('views.index.join.title1') }}</span><br />
            <span>{{ $t('views.index.join.title2') }}</span>
        </h1>

        <div class="fontBox">
            <input class="userName" type="text" :placeholder="$t('views.index.join.from.userName.placeholder')"
                v-model="userName" />
            <input class="email" type="text" :placeholder="$t('views.index.join.from.email.placeholder')"
                v-model="email" />
            <button @click="joinChange">{{ $t('views.index.join.from.button.title') }}</button>
        </div>

        <div class="tipBox" v-if="tipFlat">
            <img src="@/assets/image/indexImage/joinSuccess.png" alt="">
            <h6>{{ $t('views.index.join.tip.title') }}</h6>
            <button @click="$router.push({ path: '/home' })">{{ $t('views.index.join.tip.button.title') }}</button>
            <p><span>{{ tipTime }}</span>{{ $t('views.index.join.tip.tipText') }}</p>
        </div>
    </div>
</template>
<script>
import {
    cipherLogin,
    submitJoinUs,
    getMemberInfo
} from '@/api/api';
let int;
export default {
    data() {
        return {
            userName: '',
            email: '',
            tipFlat: false,
            tipTime: 5,
        }
    },
    beforeDestroy() {
        clearInterval(int)
    },
    methods: {
        joinChange() {

            if ((/^\s*$/.test(this.userName))) {
                return alert(this.$t('views.index.join.tip.userName.verification'))
            }

            const emailValidate =
                /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
            if (!emailValidate.test(this.email)) {
                return alert(this.$t('views.index.join.tip.email.verification'))
            }
            submitJoinUs({ name: this.userName, email: this.email }).then(res => {
                if (res.code == 0) {
                    this.tipFlat = true;
                    int = setInterval(() => {
                        if (this.tipTime <= 0) {
                            this.$router.push({ path: '/home' })
                        }
                        this.tipTime--

                    }, 1000);
                } else {
                    alert(res.msg)
                }
            })
        }
    },

}
</script>
<style lang="scss" scoped>
h1 {
    // font-family: Alimama ShuHeiTi;
    font-weight: bold;
    font-size: 60px;
    color: #FFFFFF;
    line-height: 62px;
    margin-top: 118px;
}

.fontBox {
    margin-top: 34px;
    display: flex;
    flex-direction: column;


    input {
        width: 600px;
        height: 64px;
        border-radius: 4px;
        border: 1px solid #FFFFFF;
        color: #FFFFFF;
        box-sizing: border-box;
        padding: 0 40px;
        background: none;
        outline: none;

        // font-family: Source Han Sans CN;
        font-weight: bold;
        font-size: 16px;
        color: #FFFFFF;

        &::placeholder {
            color: #FFFFFF;
        }

        &.email {
            margin-top: 24px;
        }
    }

    button {
        width: 600px;
        height: 64px;
        margin-top: 62px;
        background: #FFFFFF;
        border-radius: 4px;
        border: none;

        // font-family: Source Han Sans CN;
        font-weight: bold;
        font-size: 20px;
        color: #333333;
    }
}

.tipBox {
    width: 1400px;
    background: #FFFFFF;
    border-radius: 6px;
    position: absolute;
    left: 50%;
    top: 60px;
    transform: translateX(-50%);
    box-shadow: beige;
    padding: 86px 0 80px;
    display: flex;
    flex-direction: column;
    align-items: center;

    img {
        height: 108px;
    }

    h6 {
        // font-family: HelloFont;
        font-weight: bold;
        font-size: 24px;
        color: #333333;
        line-height: 30px;
        margin: 34px 0 42px;
    }

    button {
        width: 444px;
        height: 64px;
        background: #D1B87F;
        box-shadow: 0px 2px 21px 0px rgba(152, 112, 65, 0.21);
        border-radius: 6px;

        // font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 16px;
        color: #FFFFFF;
    }

    p {
        // font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 14px;
        color: #333333;
        line-height: 18px;
        opacity: 0.5;
        margin-top: 15px;

        span {
            color: #D1B87F;
            font-size: 16px;
            margin-right: 2px;
        }
    }
}
</style>
